package com.mfangsoft.zhuangjialong.integration.gift.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.common.model.Page;

import com.mfangsoft.zhuangjialong.integration.gift.mapper.BaseGiftMapper;
import com.mfangsoft.zhuangjialong.integration.gift.model.BaseGift;
import com.mfangsoft.zhuangjialong.integration.gift.service.GiftService;



@Service
public class GiftServiceimpl implements GiftService {
	
	
	private static final Logger LOGGER = LoggerFactory.getLogger(GiftServiceimpl.class); 
	
	
	@Autowired
	private BaseGiftMapper baseGiftMapper;


	@Override
	public void addGift(BaseGift baseGift) {
		
		
		baseGift.setCreator(UserContext.getCurrentUserId());
		
		baseGift.setCreate_time(new Date());
		
		baseGiftMapper.addGift(baseGift);
	}


	@Override
	public List<BaseGift> selectGift(BaseGift baseGift) {
		
		 if(UserContext.getCurrentUserId().longValue()!=153){
			
			
		 }
 
		 baseGift.setCreator(UserContext.getCurrentUserId());

		 
		 
		
		 List<BaseGift> list = baseGiftMapper.selectGift(baseGift);
			
		
		
		return list;
	}


	@Override
	public BaseGift selectGiftOne(int id) {
		BaseGift baseGift = new  BaseGift();
		
		
		baseGift = baseGiftMapper.selectGiftOne(id);
		
		return baseGift;
	}


	@Override
	public void updateGiftOne(BaseGift baseGift) {
		
		baseGift.setUpdater(UserContext.getCurrentUserId());
		
		baseGift.setUpdate_time(new Date());
		
		
		baseGiftMapper.updateGiftOne(baseGift);
		Map<String,Object> map=new HashMap<>();
		map.put("gift", baseGift.getGrade()+" "+baseGift.getName());
		map.put("gift_id", baseGift.getId());
		baseGiftMapper.updateOrderGift(map);
		baseGiftMapper.updateOrderGiving(map);
	}



	@Override
	public Page<Map<String, Object>> selectGiftActivity(Page<Map<String, Object>> page) {
		
		 Map<String,Object>  param=(Map<String, Object>) page.getParam();
		 Boolean  isTop = UserContext.getCurrentUser().getId().equals("153")?true:false;
		if(UserContext.getCurrentUserId().longValue() == 153){
			/* param.put("user_create", UserContext.getCurrentUser().getUserRelationEntity().getNode3());
			*/
		 }
		 if(UserContext.getCurrentUser().getUser_level() == 3){
			 param.put("user_create", UserContext.getCurrentUser().getUserRelationEntity().getNode3());
			 
		 }
		 if(UserContext.getCurrentUser().getUser_level() == 2){
			 param.put("user_create", UserContext.getCurrentUser().getUserRelationEntity().getNode2());
			 
		 }
		 
		 param.put("user_id", UserContext.getCurrentUserId());
		
		 page.setData(baseGiftMapper.selectGiftActivityPage(page));
		 page.setIsTop_level(isTop);
		 	
		return page;
	}





	


}
